




//
//  ApplyRefundSecond.m
//  XJMCustomer
//
//  Created by Mr.hu on 2017/10/23.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import "ApplyRefundSecond.h"
#import "RefundSubSecondCell.h"
#import "RefundStatusPay.h"

@interface ApplyRefundSecond ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *SubItemLab;
@property (weak, nonatomic) IBOutlet UILabel *SubtimePrice;

@property (weak, nonatomic) IBOutlet UILabel *SubRefundPrice;
@property (weak, nonatomic) IBOutlet UITextField *SubRefundDetailCause;
@property (weak, nonatomic) IBOutlet UIButton *SubSubmitBtn;

@property (weak, nonatomic) IBOutlet UIView *RefundPopupView;
@property (weak, nonatomic) IBOutlet UITableView *RefundPopTabView;
@property (nonatomic,strong) NSArray * Refund_causeArr;
@property (weak, nonatomic) IBOutlet UIButton *Refund_CloseBtn;
@property (weak, nonatomic) IBOutlet UIButton *ChoiceSelect_Cause;

@end

@implementation ApplyRefundSecond

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:NO];
    [self addLeftBtn:[UIImage imageNamed:@"fanhui"] Action:@selector(backToPrevious)];
    self.title = @"申请退款";
    
    self.SubSubmitBtn.layer.cornerRadius = 22;
    self.SubSubmitBtn.layer.masksToBounds = YES;
    self.RefundPopupView.hidden = YES;
    self.Refund_causeArr = [NSArray array];
    [self refundServerData];
    
    self.SubRefundDetailCause.delegate = self;
    self.SubRefundDetailCause.keyboardType = UIReturnKeyDone;
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jkr_tapGestureAction:)];
    tapGestureRecognizer.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapGestureRecognizer];
}

- (void)jkr_tapGestureAction:(UITapGestureRecognizer *)tapGusture{
    
    [self.view endEditing:YES];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.SubRefundDetailCause resignFirstResponder];
    
    return NO;
}

- (void)refundServerData{
    
    [LoadingView showCircleView: self.RefundPopTabView];
    /*
    [XJHttpClass RefundInformationtoken:[XJToolClass getToken] order_sn:_Refund_order_sn andFinishblock:^(id response, NSString *errStr) {
        if (errStr) {
            [XJToolClass tipAnimationWith:errStr];
        }else{
            NSDictionary * dictarr = response[@"data"];
            self.SubItemLab.text = dictarr[@"goods_name"];
            self.SubtimePrice.text = [NSString stringWithFormat:@"%@元/%@分钟",dictarr[@"goods_price"],dictarr[@"server_time"]];
            self.SubRefundPrice.text = dictarr[@"order_amount"];
            
            [LoadingView hide];
            //选退款原因
            [XJHttpClass RefundCauseInformationtoken:[XJToolClass getToken] order_sn:_Refund_order_sn andFinishblock:^(id response, NSString *errStr) {
                
                if (errStr) {
                    [XJToolClass tipAnimationWith:errStr];
                }else{
                    self.Refund_causeArr = response[@"data"];
                    
                }
            }];
        }
    }];
     */
}

- (IBAction)RefundCauseMeth:(id)sender {
    
    self.RefundPopupView.hidden = NO;
    
    self.RefundPopTabView.delegate = self;
    self.RefundPopTabView.dataSource = self;
    self.RefundPopTabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.RefundPopTabView registerNib:[UINib nibWithNibName:@"RefundSubSecondCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"RefundSubSecondCell"];
    [self.RefundPopTabView reloadData];
}

#pragma mark - TableViewDatasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self.Refund_causeArr isKindOfClass:[NSArray class]]) {
        return self.Refund_causeArr.count;
    }else{
        return 0;
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        
    RefundSubSecondCell * friend=[tableView dequeueReusableCellWithIdentifier:@"RefundSubSecondCell" forIndexPath:indexPath];
    if(friend==nil){
        friend=[[RefundSubSecondCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"RefundSubSecondCell"];
    }
    
    [friend setdata:self.Refund_causeArr[indexPath.row]];
    
     return friend;
}

#pragma mark TableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.view endEditing:YES];
    
    RefundSubSecondCell * subsec = [tableView cellForRowAtIndexPath:indexPath];
    [subsec.SelectBtn_status setBackgroundImage:[UIImage imageNamed:@"icon_lab"] forState:UIControlStateNormal];
    
    self.RefundPopupView.hidden = YES;
    self.SubRefundPrice.text = self.Refund_causeArr[indexPath.row][@"refund_money"];
    [self.ChoiceSelect_Cause setTitle:self.Refund_causeArr[indexPath.row][@"desc"] forState:UIControlStateNormal];
}


- (IBAction)RefundSubmitMeth:(id)sender {
    
    /*
    [XJHttpClass submitRefundCauseInformationtoken:[XJToolClass getToken] order_sn:self.Refund_order_sn refund_desc:self.SubRefundDetailCause.text refund_money:self.SubRefundPrice.text refund_note:@"无备注" andFinishblock:^(id response, NSString *errStr) {
        
        if (errStr) {
            [XJToolClass tipAnimationWith:errStr];
        }else{
            RefundStatusPay * minecollect = [[RefundStatusPay alloc]init];
            minecollect.SubmitRefund_order_sn = self.Refund_order_sn;
            minecollect.SubmitRefund_refund_desc = self.SubRefundDetailCause.text;
            minecollect.SubmitRefund_refund_money = self.SubRefundPrice.text;
            minecollect.SubmitRefund_refund_note = @"无备注";
            [self.navigationController pushViewController:minecollect animated:YES];
        }
        
    }];
     */
}

- (IBAction)Refund_closeOrderMeth:(id)sender {
    self.RefundPopupView.hidden = YES;
}


@end
